//
//  PlayInfoViewController.m
//  Runner
//
//  Created by 小二同學 on 2020/3/31.
//  Copyright © 2020 The Chromium Authors. All rights reserved.
//

#import "PlayInfoViewController.h"
#import <WebKit/WebKit.h>
#import "WXApi.h""

@interface PlayInfoViewController ()<WKUIDelegate,WKNavigationDelegate>

@property (nonatomic, strong) UILabel *playName;
@property (nonatomic, strong) UIImageView *portraitImage;
@property (nonatomic, strong) UILabel *uesrName;
@property (nonatomic, strong) UILabel *nameContent;
@property (nonatomic, strong) UITextView *playContent;
@property (nonatomic, strong) UILabel *liveNumber;
@property (nonatomic, strong) UILabel *ssjgLabel;
@property (nonatomic, strong) UIButton *payButton;
@property(nonatomic,strong) WKWebView * webView;
@property (nonatomic, strong) UIImageView *starImage;
@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) UIView *nameLine;
@property (nonatomic, strong) UILabel *nameInfo;

@property (nonatomic, strong) UIView *playLine;
@property (nonatomic, strong) UILabel *playInfoName;

@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIView *line1;

@property (nonatomic, strong) NSDictionary *detailDic;
@property (strong,nonatomic) AFHTTPSessionManager *mgr;

@property (nonatomic,strong) NSTimer *timer;

@property (nonatomic,strong) UIButton *payBackView;
@property (nonatomic,strong) UIImageView *zfbsImage;
@property (nonatomic,strong) UIImageView *wxsImage;
@property (strong, nonatomic) NSString *rechargeType;
@property (strong, nonatomic) UIButton *shareButton; // 分享

@property (nonatomic,strong) UIImageView *liveInfoImageView;//详情 图片

@end

@implementation PlayInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.rechargeType = @"zfb";
}

- (void)getLiveNum {
    NSString *token = [[NSUserDefaults standardUserDefaults] valueForKey:@"TOKEN"];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setValue:token forKey:@"token"];
    [params setValue:self.detailDic[@"id"] forKey:@"liveId"];
    
    AFHTTPSessionManager *manager = [self getManager];
    [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Authorization"];
    [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Access-Token"];
    
    [manager POST:[NSString stringWithFormat:@"%@v1/live/view",API_URL] parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        NSLog(@"%@",dic);
        
        NSString *code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        if ([code isEqual:@"0"]) {
            NSString *status = [NSString stringWithFormat:@"%@",self.detailDic[@"status"]];
            NSDictionary *data = dic[@"data"];
            NSString *count_user = [NSString stringWithFormat:@"%@",data[@"countUser"]];
            if (kStringIsEmpty(count_user) == NO) {
                if ([status isEqual:@"0"]) {
                    self.liveNumber.text = [NSString stringWithFormat:@"%@人已预约 |",count_user];
                }else if ([status isEqual:@"1"]) {
                    self.liveNumber.text = [NSString stringWithFormat:@"%@人在学习 |",count_user];
                }else if ([status isEqual:@"2"]) {
                    self.liveNumber.text = [NSString stringWithFormat:@"%@人已学习 |",count_user];
                }
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self.timer invalidate];
    self.timer = nil;
}

- (void)setUI {
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - [UIScreen mainScreen].bounds.size.width * 9/16 - 50)];
    [self.view addSubview:self.scrollView];
    
    [self.scrollView addSubview:self.portraitImage];
    [self.scrollView addSubview:self.playContent];
    [self.scrollView addSubview:self.uesrName];
    [self.scrollView addSubview:self.liveNumber];
    [self.scrollView addSubview:self.ssjgLabel];
    [self.scrollView addSubview:self.playName];
    [self.view addSubview:self.payButton];
    [self.scrollView addSubview:self.nameContent];
//    [self.scrollView addSubview:self.nameInfo];
    [self.scrollView addSubview:self.liveInfoImageView];
//    [self.scrollView addSubview:self.nameLine];
    [self.scrollView addSubview:self.playInfoName];
    [self.scrollView addSubview:self.shareButton];
//    [self.scrollView addSubview:self.playLine];
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:self.payBackView];
    
    for (int i =0; i < 5; i++) {
        self.starImage = [[UIImageView alloc] initWithFrame:CGRectMake(20*i+82, 65, 20, 20)];
        self.starImage.image = [UIImage imageNamed:@"live_star"];
        [self.scrollView addSubview:self.starImage];
    }
    
    self.line = [[UIView alloc] initWithFrame:CGRectMake(0, 310, [UIScreen mainScreen].bounds.size.width, 10)];
    self.line.backgroundColor = UIColorFromRGB(0xfff6f6f6);
    [self.scrollView addSubview:self.line];
    
    self.line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 170, [UIScreen mainScreen].bounds.size.width, 10)];
    self.line1.backgroundColor = UIColorFromRGB(0xfff6f6f6);
    [self.scrollView addSubview:self.line1];
    
    UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 10)];
    line2.backgroundColor = UIColorFromRGB(0xfff6f6f6);
    [self.scrollView addSubview:line2];
}

- (void)sendPlayInfo:(NSDictionary *)dic {
    [self setUI];
    [self getVideoInfoWithVideoId:dic];
    [self getLiveNum];
}

- (void)getVideoInfoWithVideoId:(NSDictionary *)dic {
    
    self.detailDic = [NSDictionary dictionaryWithDictionary:dic];
    
    //间隔1s请求在线人数
    self.timer = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(getLiveNum) userInfo:nil repeats:YES];
    
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://ahj-jiaoyu-test.oss-cn-beijing.aliyuncs.com/%@",dic[@"teacherAvatar"]]]];
    self.portraitImage.image = [UIImage imageWithData:data];
    if (kStringIsEmpty(self.detailDic[@"teacherIntro"]) == NO) {
        self.nameContent.text = [NSString stringWithFormat:@"%@",self.detailDic[@"teacherIntro"]];
    }
    
    NSString *ssjg = [NSString stringWithFormat:@"%@",self.detailDic[@"agentName"]];
    if (kStringIsEmpty(ssjg) == NO) {
        self.ssjgLabel.frame = CGRectMake(20, 90, [UIScreen mainScreen].bounds.size.width - 40, 30);
        self.ssjgLabel.text = [NSString stringWithFormat:@"所属机构：%@",ssjg];
    }else {
        self.ssjgLabel.frame = CGRectMake(20, 90, [UIScreen mainScreen].bounds.size.width - 40, 1);
    }
    self.line1.frame = CGRectMake(0, CGRectGetMaxY(self.ssjgLabel.frame) + 10, [UIScreen mainScreen].bounds.size.width, 10);

//    self.avatarImageView.frame = CGRectMake(15, CGRectGetMaxY(self.line1.frame) + 10, 48, 48);
//    self.nameInfo.frame = CGRectMake(48+12, CGRectGetMaxY(self.line1.frame) + 10, 100, 40);
//    self.nameLine.frame = CGRectMake(20, CGRectGetMaxY(self.line1.frame) + 15, 3, 25);
    self.portraitImage.frame = CGRectMake(15, CGRectGetMaxY(self.line1.frame) + 10, 48, 48);
    self.uesrName.frame = CGRectMake(75, CGRectGetMaxY(self.line1.frame) + 19, 100, 30);

    CGSize size = [self.nameContent.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, MAXFLOAT)
                                              options:NSStringDrawingUsesLineFragmentOrigin
                                           attributes:@{NSFontAttributeName:self.nameContent.font}
                                              context:nil].size;
    self.nameContent.frame = CGRectMake(20, CGRectGetMaxY(self.portraitImage.frame) + 10, [UIScreen mainScreen].bounds.size.width - 40, size.height);
    self.line.frame = CGRectMake(0, CGRectGetMaxY(self.nameContent.frame) + 10, [UIScreen mainScreen].bounds.size.width, 10);
//    self.playLine.frame = CGRectMake(20, CGRectGetMaxY(self.line.frame) + 10, 3, 25);
    self.liveInfoImageView.frame = CGRectMake(20, CGRectGetMaxY(self.line.frame) + 10, 20, 20);
    self.playInfoName.frame = CGRectMake(50, CGRectGetMaxY(self.line.frame), 100, 40);
    
    if (kStringIsEmpty(self.detailDic[@"title"]) == NO) {
        self.playName.text = [NSString stringWithFormat:@"%@",self.detailDic[@"title"]];
    }
    
    NSString *content = [NSString stringWithFormat:@"%@",self.detailDic[@"content"]];
    if (kStringIsEmpty(content) == NO) {
        self.playContent.attributedText = [self showAttributedToHtml:content withWidth:[UIScreen mainScreen].bounds.size.width - 40];
        
        CGFloat height = [self.playContent.attributedText boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height;
        self.playContent.frame = CGRectMake(20, CGRectGetMaxY(self.playInfoName.frame), [UIScreen mainScreen].bounds.size.width - 40, height);
    }
    
    self.scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, CGRectGetMaxY(self.playContent.frame) + 50);
    
    if (kStringIsEmpty(self.detailDic[@"teacherTruename"]) == NO) {
        self.uesrName.text = [NSString stringWithFormat:@"%@",self.detailDic[@"teacherTruename"]];
    }    
    
    
//    self.liveNumber.text = [NSString stringWithFormat:@"%@人正在学习",self.detailDic[@"nums"]];
    NSString *price = [NSString stringWithFormat:@"%@",self.detailDic[@"price"]];
    NSString *buy_status = [NSString stringWithFormat:@"%@",self.detailDic[@"price"]];
    NSString *apply_status = [NSString stringWithFormat:@"%@",self.detailDic[@"applyStatus"]];
    NSString *status = [NSString stringWithFormat:@"%@",self.detailDic[@"status"]];
    
    if ([status isEqual:@"0"]) {
        self.payButton.hidden = NO;
        if ([apply_status isEqual:@"0"]) {
            [self.payButton setTitle:@"预约" forState:UIControlStateNormal];
        }else {
            self.payButton.enabled = NO;
            [self.payButton setTitle:@"已预约" forState:UIControlStateNormal];
        }
    }else {
        if (price.doubleValue == 0.00) {
            self.payButton.hidden = YES;
        }else {
            if ([buy_status isEqual:@"1"]) {
                self.payButton.hidden = YES;
            }else {
                self.payButton.hidden = NO;
            }
        }
    }
}

///显示富文本
- (NSAttributedString *)showAttributedToHtml:(NSString *)html withWidth:(float)width{
//替换图片的高度为屏幕的高度
    NSString *newString = [html stringByReplacingOccurrencesOfString:@"<img" withString:[NSString stringWithFormat:@"<img width=\"%f\"",width]];
    
    NSAttributedString *attributeString=[[NSAttributedString alloc] initWithData:[newString dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
     
    return attributeString;
 
}

- (void)buttonAction {
    NSString *status = [NSString stringWithFormat:@"%@",self.detailDic[@"status"]];
    NSString *price = [NSString stringWithFormat:@"%@",self.detailDic[@"price"]];
    NSString *buy_status = [NSString stringWithFormat:@"%@",self.detailDic[@"price"]];
    
    if (price.doubleValue == 0.00) {
        if ([status isEqual:@"0"]) {
            [self YuYue];
        }
    }else {
        if ([buy_status isEqual:@"1"]) {
            if ([status isEqual:@"0"]) {
                [self YuYue];
            }
        }else {
            [self goToPay];
        }
    }
}

#pragma mark - 预约
- (void)YuYue {
    NSString *token = [[NSUserDefaults standardUserDefaults] valueForKey:@"TOKEN"];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setValue:token forKey:@"token"];
    [params setValue:self.detailDic[@"id"] forKey:@"id"];
    
    AFHTTPSessionManager *manager = [self getManager];
    [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Authorization"];
    [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Access-Token"];
    
    [manager POST:[NSString stringWithFormat:@"%@v1/live/apply",API_URL] parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        NSLog(@"%@",dic);
        NSString *code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        if ([code isEqual:@"0"]) {
            [self.payButton setTitle:@"已预约" forState:UIControlStateNormal];
            self.payButton.enabled = NO;
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}

#pragma mark 支付
- (void)zfb {
    self.rechargeType = @"zfb";
    self.wxsImage.image = [UIImage imageNamed:@"zf"];
    self.zfbsImage.image = [UIImage imageNamed:@"zf_s"];
}

- (void)wx {
    self.rechargeType = @"wx";
    self.wxsImage.image = [UIImage imageNamed:@"zf_s"];
    self.zfbsImage.image = [UIImage imageNamed:@"zf"];
}

- (void)goToPay {
    self.payBackView.hidden = NO;
}

- (void)hideView {
    self.payBackView.hidden = YES;
}

- (void)bottomPay {
    AFHTTPSessionManager *manager = [self getManager];
    NSString *token = [[NSUserDefaults standardUserDefaults] valueForKey:@"TOKEN"];
    [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Authorization"];
    [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Access-Token"];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setValue:self.detailDic[@"id"] forKey:@"itemId"];
    [params setValue:@"3" forKey:@"type"];
    [params setValue:token forKey:@"token"];

    [manager POST:[NSString stringWithFormat:@"%@v1/pay/check",API_URL] parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary *dic = (NSDictionary *)responseObject;
        NSString *code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        if ([code isEqual:@"0"]) {
            NSLog(@"%@",dic);
            NSDictionary *data = dic[@"data"];

            NSMutableDictionary *params1 = [[NSMutableDictionary alloc] init];
            [params1 setValue:self.detailDic[@"id"] forKey:@"itemId"];
            [params1 setValue:@"3" forKey:@"type"];
            [params1 setValue:data[@"orderNo"] forKey:@"orderNo"];
            [params1 setValue:token forKey:@"token"];

            [manager POST:[NSString stringWithFormat:@"%@v1/pay/create",API_URL] parameters:params1 headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

                NSDictionary *dic2 = (NSDictionary *)responseObject;
                NSDictionary *dataDic2 = dic2[@"data"];

                NSMutableDictionary *params2 = [[NSMutableDictionary alloc] init];
                if ([self.rechargeType isEqual:@"zfb"]) {
                    [params2 setValue:@"alipay" forKey:@"payment"];
                }else {
                    [params2 setValue:@"H5wechat" forKey:@"payment"];
                }
                [params2 setValue:dataDic2[@"orderNo"] forKey:@"orderNo"];
                [params2 setValue:token forKey:@"token"];

                [manager POST:[NSString stringWithFormat:@"%@v1/pay/payment",API_URL] parameters:params2 headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

                    NSDictionary *dic3 = (NSDictionary *)responseObject;
                    NSDictionary *data3 = dic3[@"data"];

                    self.webView = [[WKWebView alloc]initWithFrame:CGRectZero];
                    self.webView.UIDelegate = self;
                    self.webView.navigationDelegate = self;

                    NSMutableURLRequest * request  = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:data3[@"payinfo"]]];
                    [request setValue:@"api.xinanyun.cn//" forHTTPHeaderField:@"Referer"];
                    [self.webView loadRequest:request];
                    [self.view addSubview:self.webView];

                    NSLog(@"%@",data3);

                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                }];

            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            }];
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}

- (void)share {
    WXWebpageObject *webpageObject = [WXWebpageObject object];
    webpageObject.webpageUrl = [NSString stringWithFormat:@"http://leaflet.anhuanjia.com/#/?type=3&id=%@",self.detailDic[@"id"]];
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = [NSString stringWithFormat:@"%@",self.detailDic[@"title"]];
    message.description = [NSString stringWithFormat:@"%@",self.detailDic[@"content"]];
    NSString *imageUrl = [NSString stringWithFormat:@"%@",self.detailDic[@"imageUrl"]];
    if (kStringIsEmpty(imageUrl)) {
        imageUrl = @"";
    }
    NSData *compressData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
    UIImage *image = [UIImage imageWithData:compressData];
    compressData = UIImageJPEGRepresentation(image, 0.1);
    [message setThumbImage:[UIImage imageWithData:compressData]];
                            
    message.mediaObject = webpageObject;
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneSession;
    
    weixin://wap/pay?prepayid%3Dwx06094454714147e5025508723b6e340000&package=4218714087&noncestr=1604627101&sign=43a491eaf14d351ee93144b7938d8955&redirect_url=uu.qunayue.com
    
//    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
//    req.bText = YES;
//    req.text = dic[@"url"];
//    req.scene = WXSceneSession;
    [WXApi sendReq:req completion:^(BOOL success) {
        
    }];
}

-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    NSURL *URL = navigationAction.request.URL;
    NSString * urlStr = URL.absoluteString;
    if([urlStr containsString:@"weixin://wap"]) {
        if (![urlStr containsString:@"redirect_url="]) {
            NSString * redirect = @"&redirect_url=api.xinanyun.cn";
            urlStr = [urlStr stringByAppendingString:redirect];
        }
        NSURL * url = [NSURL URLWithString:urlStr];
        NSLog(@"%@",url);
        [[UIApplication sharedApplication] openURL:url];
        decisionHandler(WKNavigationActionPolicyCancel);
        return;
    }
    decisionHandler(WKNavigationActionPolicyAllow);
}

- (UIView *)nameLine {
    if (!_nameLine) {
        _nameLine = [[UIView alloc] initWithFrame:CGRectMake(20, 125, 3, 25)];
        _nameLine.backgroundColor = UIColorFromRGB(0xFF1a73e8);
        _nameLine.layer.masksToBounds = YES;
        _nameLine.layer.cornerRadius = 4;
    }
    return _nameLine;
}

- (UILabel *)nameInfo {
    if (!_nameInfo) {
        _nameInfo = [[UILabel alloc] initWithFrame:CGRectMake(30, 120, 100, 40)];
        _nameInfo.numberOfLines = 1;
        _nameInfo.text = @"老师介绍";
        _nameInfo.font = [UIFont boldSystemFontOfSize:16];
        _nameInfo.textColor = UIColorFromRGB(0xff333333);
    }
    return _nameInfo;
}

- (UIView *)playLine {
    if (!_playLine) {
        _playLine = [[UIView alloc] initWithFrame:CGRectMake(20, 105, 3, 25)];
        _playLine.backgroundColor = UIColorFromRGB(0xFF1a73e8);
        _playLine.layer.masksToBounds = YES;
        _playLine.layer.cornerRadius = 4;
    }
    return _playLine;
}

- (UILabel *)playInfoName {
    if (!_playInfoName) {
        _playInfoName = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 100, 40)];
        _playInfoName.numberOfLines = 1;
        _playInfoName.text = @"课程详情";
        _playInfoName.font = [UIFont boldSystemFontOfSize:16];
        _playInfoName.textColor = UIColorFromRGB(0xff333333);
    }
    return _playInfoName;
}

- (UILabel *)playName {
    if (!_playName) {
        _playName = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, [UIScreen mainScreen].bounds.size.width - 100, 40)];
        _playName.numberOfLines = 1;
        _playName.font = [UIFont boldSystemFontOfSize:16];
        _playName.textColor = UIColorFromRGB(0xff222222);
    }
    return _playName;
}

- (UIButton *)payButton {
    if (!_payButton) {
        _payButton = [[UIButton alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - ([UIScreen mainScreen].bounds.size.width * 9/16) - GK_SAFEAREA_BTM - 90, [UIScreen mainScreen].bounds.size.width, 60)];
        [_payButton setTitle:@"购买" forState:UIControlStateNormal];
        _payButton.backgroundColor = UIColorFromRGB(0xff1296db);
        _payButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_payButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
        _payButton.hidden = YES;
    }
    return _payButton;
}

- (UIButton *)payBackView {
    if (!_payBackView) {
        _payBackView = [[UIButton alloc] initWithFrame:self.view.bounds];
        _payBackView.hidden = YES;
        [_payBackView addTarget:self action:@selector(hideView) forControlEvents:UIControlEventTouchUpInside];
        _payBackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
        
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(30, 200, ([UIScreen mainScreen].bounds.size.height - 60)/2, 250)];
        backView.backgroundColor = [UIColor whiteColor];
        backView.layer.masksToBounds = YES;
        backView.layer.cornerRadius = 8;
        [self.payBackView addSubview:backView];
        
        UIImageView *zfbImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 25, 25)];
        zfbImage.image = [UIImage imageNamed:@"ad_333"];
        [backView addSubview:zfbImage];
        
        UILabel *zfbLabel = [[UILabel alloc] init];
        zfbLabel.text = @"支付宝";
        zfbLabel.font = [UIFont systemFontOfSize:16];
        [backView addSubview:zfbLabel];
        [zfbLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(zfbImage);
            make.left.equalTo(zfbImage.mas_right).offset(50);
        }];
        
        self.zfbsImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zf_s"]];
        [backView addSubview:self.zfbsImage];
        [self.zfbsImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backView).offset(-20);
            make.centerY.equalTo(zfbImage);
        }];
        
        UIButton *zfbButton = [[UIButton alloc] init];
        [zfbButton addTarget:self action:@selector(zfb) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:zfbButton];
        [zfbButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(backView);
            make.top.equalTo(zfbImage);
            make.height.mas_equalTo(50);
        }];
        
        UIImageView *wxImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_444"]];
        [backView addSubview:wxImage];
        [wxImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backView).offset(20);
            make.top.equalTo(zfbButton.mas_bottom).offset(20);
            make.width.height.mas_equalTo(25);
        }];
        
        UILabel *wxLabel = [[UILabel alloc] init];
        wxLabel.text = @"微信";
        wxLabel.font = [UIFont systemFontOfSize:16];
        [backView addSubview:wxLabel];
        [wxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(wxImage);
            make.left.equalTo(wxImage.mas_right).offset(50);
        }];
        
        self.wxsImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zf"]];
        [backView addSubview:self.wxsImage];
        [self.wxsImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backView).offset(-20);
            make.centerY.equalTo(wxImage);
        }];
        
        UIButton *wxButton = [[UIButton alloc] init];
        [wxButton addTarget:self action:@selector(wx) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:wxButton];
        [wxButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(backView);
            make.top.equalTo(wxImage);
            make.height.mas_equalTo(50);
        }];
        
        UIButton *payBottomButton = [[UIButton alloc] init];
        [payBottomButton setTitle:@"立即购买" forState:UIControlStateNormal];
        [payBottomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        payBottomButton.backgroundColor = UIColorFromRGB(0x5DC691);
        payBottomButton.layer.masksToBounds = YES;
        [payBottomButton addTarget:self action:@selector(bottomPay) forControlEvents:UIControlEventTouchUpInside];
        payBottomButton.layer.cornerRadius = 22;
        [backView addSubview:payBottomButton];
        [payBottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backView).offset(20);
            make.right.equalTo(backView).offset(-20);
            make.top.equalTo(wxButton.mas_bottom).offset(15);
            make.height.mas_equalTo(43);
        }];
    }
    return _payBackView;
}

- (UIImageView *)portraitImage {
    if (!_portraitImage) {
        _portraitImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 190, 58, 58)];
        _portraitImage.layer.masksToBounds = YES;
        _portraitImage.image = [UIImage imageNamed:@"morentouxiang"];
        _portraitImage.layer.cornerRadius = 24;
    }
    return _portraitImage;
}

- (UILabel *)uesrName {
    if (!_uesrName) {
        _uesrName = [[UILabel alloc] initWithFrame:CGRectMake(75, 190, 100, 30)];
        _uesrName.numberOfLines = 1;
        _uesrName.font = [UIFont systemFontOfSize:15];
        _uesrName.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
        _uesrName.textColor = UIColorFromRGB(0xff131313);
    }
    return _uesrName;
}

- (UILabel *)liveNumber {
    if (!_liveNumber) {
        _liveNumber = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 100, 30)];
        _liveNumber.numberOfLines = 1;
        _liveNumber.font = [UIFont systemFontOfSize:12];
        _liveNumber.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
    }
    return _liveNumber;
}

- (UIButton *)shareButton {
    if (!_shareButton) {
        _shareButton = [[UIButton alloc] initWithFrame:CGRectMake(GK_SCREEN_WIDTH - 80, 50, 80, 30)];
        [_shareButton setTitle:@"分享" forState:UIControlStateNormal];
        [_shareButton addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
        [_shareButton setTitleColor:UIColorFromRGB(0xff131313) forState:UIControlStateNormal];
    }
    return _shareButton;
}

- (UILabel *)ssjgLabel {
    if (!_ssjgLabel) {
        _ssjgLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 90, 100, 30)];
        _ssjgLabel.numberOfLines = 1;
        _ssjgLabel.font = [UIFont systemFontOfSize:16];
        _ssjgLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
    }
    return _ssjgLabel;
}

- (UILabel *)nameContent {
    if (!_nameContent) {
        _nameContent = [[UILabel alloc] initWithFrame:CGRectMake(20, 240, [UIScreen mainScreen].bounds.size.width - 40, 60)];
        _nameContent.numberOfLines = 0;
        _nameContent.font = [UIFont systemFontOfSize:14];
        _nameContent.textColor = UIColorFromRGB(0x666666);
    }
    return _nameContent;
}

- (UITextView *)playContent {
    if (!_playContent) {
        _playContent = [[UITextView alloc] initWithFrame:CGRectMake(20, 310, [UIScreen mainScreen].bounds.size.width - 40, 150)];
        _playContent.editable = NO;
        _playContent.scrollEnabled = NO;
        _playContent.backgroundColor = [UIColor whiteColor];
        _playContent.font = [UIFont systemFontOfSize:12];
        _playContent.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
    }
    return _playContent;
}
- (UIImageView *)liveInfoImageView{

    if (!_liveInfoImageView) {
        _liveInfoImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
//        _liveInfoImageView.layer.cornerRadius = 24;
        _liveInfoImageView.image = [UIImage imageNamed:@"live_info"];
        _liveInfoImageView.clipsToBounds = YES;
//        _liveInfoImageView.backgroundColor = UIColor.redColor;

    }
    return _liveInfoImageView;
}

- (AFHTTPSessionManager *)getManager
{
    _mgr = [AFHTTPSessionManager manager];
    [_mgr.requestSerializer setTimeoutInterval:10];
    _mgr.responseSerializer = [AFJSONResponseSerializer serializer];
    _mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/javascript",@"text/html",@"text/plain",nil];
    _mgr.requestSerializer = [AFJSONRequestSerializer serializer];
    _mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    return _mgr;
}

- (void)dealloc {
    [self.timer invalidate];
    self.timer = nil;
}
@end
